<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>与对应负数同时存在的最大正整数</title>
</head>
<body>
  <script>
    function fn(nums) {
      nums.sort((a, b) => a - b)
      let i = 0;
      let j = nums.length - 1;
      while (i < j) {
        if (nums[i] + nums[j] == 0) {
          return nums[j];
        } else if (nums[i] + nums[j] > 0) {
          j--;
        } else {
          i++;
        }
      }
      return -1;
    }
    console.log(fn([-1, 2, -3, 3]))
  </script>
</body>
</html>